package cn.stylefeng.guns.modular.household.controller;

import cn.stylefeng.guns.modular.household.entity.Household;
import cn.stylefeng.guns.modular.household.pojo.HouseholdAddRequest;
import cn.stylefeng.guns.modular.household.pojo.HouseholdRequest;
import cn.stylefeng.guns.modular.household.pojo.dto.HouseholdDto;
import cn.stylefeng.guns.modular.household.service.HouseholdService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.annotation.BusinessLog;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 权属户管理接口
 *
 * @author lichenhui
 * @date 2024/03/20
 */
@RestController
@ApiResource(name = "权属户管理", resBizType = ResBizTypeEnum.BUSINESS)
public class HouseholdController {
    
    @Resource
    private HouseholdService householdService;

    @GetResource(name = "分页查询户基本信息", path = {"/household/page"})
    public ResponseData<PageResult<Household>> page(HouseholdRequest request) {
        return new SuccessResponseData(householdService.findPage(request));
    }

    @PostResource(name = "添加权属户", path = {"/household/add"})
    @BusinessLog
    public ResponseData<?> add(@RequestBody @Validated({HouseholdAddRequest.add.class}) HouseholdAddRequest request) {
        householdService.add(request);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除权属户", path = {"/household/delete"})
    @BusinessLog
    public ResponseData<?> delete(@RequestBody @Validated({HouseholdRequest.delete.class}) HouseholdRequest request) {
        householdService.del(request);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑权属户", path = {"/household/edit"})
    @BusinessLog
    public ResponseData<?> edit(@RequestBody @Validated({HouseholdAddRequest.edit.class}) HouseholdAddRequest request) {
        householdService.edit(request);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看权属户", path = {"/household/detail"})
    public ResponseData<HouseholdDto> detail(@Validated({HouseholdRequest.detail.class}) HouseholdRequest request) {
        return new SuccessResponseData(householdService.detail(request));
    }

}
